/* Copyright 2008 Shawn C. Dodd

This file is part of TagFC.  TagFC is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

TagFC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with TagFC.  If not, see <http://www.gnu.org/licenses/>. */

class BootStrap {

     def init = { servletContext ->
	// needed to bootstrap subscription below
	new SimpleEntry(uri:"tag:flickr.com,2005:/grouppool/26241990@N00/photo/2261362483",fullImageURL:"http://farm3.static.flickr.com/2322/2261362483_e5c60ba1f3_o.jpg",thumbnailURL:"http://farm3.static.flickr.com/2322/2261362483_cecd67b0bd_m.jpg",markupFragment:"",namespace:"flickr",tags:"").save()
	new SimpleEntry(uri:"tag:flickr.com,2005:/grouppool/26241990@N00/photo/2265065391",fullImageURL:"http://farm3.static.flickr.com/2212/2265065391_f9b1170e55_o.jpg",thumbnailURL:"http://farm3.static.flickr.com/2212/2265065391_3e3fdcd079_m.jpg",markupFragment:"",namespace:"flickr",tags:"").save()

	// need at least one subscription to a feed
//	new Subscription(url:"http://api.flickr.com/services/feeds/groups_pool.gne?id=26241990@N00&format=atom_100",modification:"",loopCount:10).save()
	def s1 = new Subscription(url:"http://api.flickr.com/services/feeds/photos_public.gne?format=atom_100",modification:"",loopCount:10)
	s1.addToSeen(namespace:"flickr",uri:"tag:flickr.com,2005:/grouppool/26241990@N00/photo/2261362483")
	if( !s1.save() ) {
		log.error "Oops! Unable to create first feed subscription:"
		s1.errors.allErrors.each { log.error "Error creating first feed subscription: ${it}" }
	}

	// add an Anonymous user
	if(!Nickname.findByDisplayName("Anonymous")) {
		log.error "Creating Nickname for Anonymous user."
		def anon = new Nickname(displayName:"Anonymous")
		if(!anon.save()) {
			log.error "Oops! Unable to create Nickname for Anonymous user:"
			anon.errors.allErrors.each { log.error "Error creating Anonymous Nickname: ${it}" }
		}
	}
     }
     def destroy = {
     }
} 
